package br.org.demolay;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		final long userId = ((GlobalState)getApplication()).getUserId();
		Thread th = new Thread(){
			@Override
			public void run(){
				br.org.demolay.webservice.Service service = new br.org.demolay.webservice.Service();
				
				final String nome = service.Nome(userId);
				runOnUiThread(new Runnable(){
					@Override
					public void run() {
						TextView saudacao = (TextView)findViewById(R.id.saudacao);
						saudacao.setText("Bem vindo " + nome.split(" ")[0]);
					}
				});
			}
		};
		
		th.start();
		
		findViewById(R.id.btnContatos).setOnClickListener(
				new View.OnClickListener() {
					@Override
					public void onClick(View view) {
						Intent intent = new Intent(MainActivity.this,ContatosActivity.class);
						startActivity(intent);
					}
				});
		
		findViewById(R.id.btnMensalidades).setOnClickListener(
				new View.OnClickListener() {
					@Override
					public void onClick(View view) {
						Intent intent = new Intent(MainActivity.this, MensalidadesActivity.class);
						startActivity(intent);
					}
				});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
